package com.itheima.model.vo;

import com.itheima.model.domain.User;
import com.itheima.model.domain.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @author zhangpei
 * @ClassName UserVo
 * @date 2022/6/20/21:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserVo implements Serializable {
    private Integer id;
    private String nickname;
    private String mobile;
    private String sex;
    private String personalSignature;  //个性签名
    private Integer age;
    private Integer countBeLiked;      //不喜欢的人数
    private Integer countLiked;        //喜欢的人数
    private Integer countMatching;     //配对数量 互相喜欢
    private Integer income;            //收入
    private String occupation;         //职业
    private String userStatus;
    private Long created;
    private String city;
    private Date lastActiveTime=new Date(System.currentTimeMillis()-360000000);    //最后活跃时间
    private String lastLoginLocation;  //最后登录地区
    private String logo;               //头像
    private String tags;               //标签

    public static UserVo init(UserInfo userInfo, User user, CountsVo countsVo) {
        UserVo userVo = new UserVo();
        if (userInfo != null) {
            BeanUtils.copyProperties(userInfo, userVo);
            userVo.setLogo(userInfo.getAvatar());
            userVo.setId(Integer.valueOf(userInfo.getId().toString()));
            userVo.setMobile(user.getMobile());
            userVo.setSex(userInfo.getGender().equals("woman") ? "女" : "男");
            userVo.setCountBeLiked(countsVo.getFanCount());
            userVo.setCountLiked(countsVo.getLoveCount());
            userVo.setCountMatching(countsVo.getEachLoveCount());
            userVo.setIncome(Integer.parseInt(userInfo.getIncome()));
            userVo.setOccupation(userInfo.getProfession());

            userVo.setCreated(userInfo.getCreated().getTime());
        }
        return userVo;
    }
}
